package com.csxy.lxl.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csxy.lxl.R;
import com.csxy.lxl.entity.EduCourse;
import com.csxy.lxl.entity.vo.ChapterVo;
import com.csxy.lxl.entity.vo.CourseFrontVo;
import com.csxy.lxl.entity.vo.CourseWebVo;
import com.csxy.lxl.service.EduChapterService;
import com.csxy.lxl.service.EduCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/coursefront")
public class CourseFrontController {
    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduChapterService eduChapterService;

    @PostMapping("getFrontCourseList/{page}/{limit}")
    public R getFrontCourseList(@PathVariable long page, @PathVariable long limit,
                                @RequestBody(required = false) CourseFrontVo courseFrontVo){
        Page<EduCourse> pageCourse = new Page<>(page,limit);
        Map<String,Object> map = eduCourseService.getCourseFrontInfo(pageCourse,courseFrontVo);
        //返回分页数据
        return R.ok().data(map);
    }

    //课程详情的方法
    @GetMapping("/getFrontCourseInfo/{courseId}")
    public R getFrontCourseInfo(@PathVariable String courseId){
        //1.根据课程id，查询课程基本信息
        CourseWebVo courseWebVo = eduCourseService.getBaseCourseInfo(courseId);
        //2.根据课程id，查询章节和小节
        List<ChapterVo> chapterVoList = eduChapterService.getChapterVideoByCourseId(courseId);
        return R.ok().data("courseWebVo",courseWebVo).data("chapterVideoList",chapterVoList);
    }
}
